public class BatchApexController {
    ID batchprocessid;
    Static public String BatchName='Test';
    public String ItemsProcessed{get;set;}
    public String ItemsRemaining{get;set;}
    Integer count=0;
    public Boolean Complete{get;set;}
    public static Boolean flag = false;
    public BatchApexController(){
        ItemsProcessed = '0';
        ItemsRemaining = '0';
        Complete=false;
    }
    public void startBatch(){
        Complete= true;
        ItemsProcessed = '0';
        ItemsRemaining = '0';
        System.debug('In Start Batch');
        TstBatchApex batApx = new TstBatchApex('Select Name from Batch__c');
        batchprocessid = Database.executeBatch(batApx);
    }
    public void monitorBatch(){
        System.debug('In Monitor Batch'+count);
        count++;
        AsyncApexJob aaj = [SELECT Id, Status, JobItemsProcessed, TotalJobItems, NumberOfErrors 
        FROM AsyncApexJob WHERE ID =: batchprocessid ];
        ItemsProcessed = String.valueOf(aaj.JobItemsProcessed);
        ItemsRemaining = String.valueOf(aaj.TotalJobItems - aaj.JobItemsProcessed);
        if(aaj.Status.equals('Completed')){
            Complete = false;
        }
        if(flag==true){
            flag = false;
        }
        else{
            flag = true;
        }
        System.debug('*********'+flag);
    }
}